<?php
	$root = 'http://mao';

	/* Open MySQL connection and prepare database used in this application.
	   The link to DB should be kept only when necessary, so after getting this
	   connection do your SQL job and close it. */ 
	function get_connection($dbName) {
		$con = mysql_pconnect('mao', 'root', 'qwerty123', 65536);
		if (!$con) {
			echo('<h3 style="color: Red;">Cannot connect to MySQL server &nbsp;&nbsp; :\'(</h3>');
			die('Could not connect: ' . mysql_error());
		}
		mysql_query("SET NAMES 'utf8'");
		mysql_select_db($dbName, $con);
		return $con;
	}
	
	
	function get_connection2() {
		$con = mysql_pconnect('server38.000webhost.com', 'a3195953_dwhuser', 'qwerty012', 65536);
		if (!$con) {
			echo('<h3 style="color: Red;">Cannot connect to MySQL server &nbsp;&nbsp; :\'(</h3>');
			die('Could not connect: ' . mysql_error());
		}
		mysql_query("SET NAMES 'utf8'");
		mysql_select_db("a3195953_DWH", $con);
		return $con;
	}
	
	
	

	/* Calls MySQL stored function and returns it's return value or throws
	   an exception if the there is nothing to be returned.
	   Needed connection is open and closed automatically. */
	function mysql_call_func($funcName) {
		$con = get_connection();
		$result = mysql_query('SELECT ' .$funcName) or mysql_close($con);
		if(!$result) die(mysql_error());
		$row = mysql_fetch_array($result);
		return $row[0];
		mysql_close($con);
	}
?>

	
	
	
	
	
	
	
	
	
	
	
	
